package com;

import java.util.Vector;

import de.dfki.util.xmlrpc.XmlRpc.Type;
import de.dfki.util.xmlrpc.conversion.Convertable;
import de.dfki.util.xmlrpc.conversion.TypeConversionException;

@de.dfki.util.xmlrpc.annotation.XmlRpc(type = Type.ARRAY)
public class PeerData implements Convertable<Vector<String>>{

	public String name = "P1";
	public String address = "localhost";
	public int port = 6666;
	public int capacity = 10;
	
	public PeerData( Vector<String> xmlRpcRepresentation ) { 
		name = (String) xmlRpcRepresentation.toArray()[0];
		address = (String) xmlRpcRepresentation.toArray()[1];
		port = Integer.parseInt((String) xmlRpcRepresentation.toArray()[2]);
		capacity = Integer.parseInt((String) xmlRpcRepresentation.toArray()[3]);
	}

	@Override
	public Vector<String> toXmlRpc() throws TypeConversionException {
		Vector<String> a = new Vector<String>();
		a.add(name);
		a.add(address);
		a.add(""+port);
		a.add(""+capacity);
		return a;
	}

	@Override
	public boolean equals(Object o){
		PeerData opd;
		if(!(o instanceof PeerData))
			return false;
		opd = (PeerData)o;
		if(name.equals(opd.name) && address.equals(opd.address) && port == opd.port)
			return true;
		else
			return false;
	}
}
